package org.wei.rssreader;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.dualr.litelog.dao.PMF;

/**
 * RssDAO.java 
 */
public class RssDAO {
	static PersistenceManager pm = PMF.get().getPersistenceManager();
	
	/**
	 * 保存一个rss源
	 * @param source
	 * @return
	 */
	public static Long insert(RssSourceBO source) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(source);
		} finally {
			pm.close();
		}
		return source.getId();
	}
	
	// get all rss源
	@SuppressWarnings("unchecked")
	public static List<RssSourceBO> getAll() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(RssSourceBO.class);
		try {
			return (List<RssSourceBO>) query.execute();
		} finally {
			query.closeAll();
		}
	}

}
